<template>
  <div>
    <a-card :bordered="false">
      <f-search-form :more="false" @searchHandler="searchHandler">
        <f-search-form-item label="流程名称" name="categoryName"/>
        <f-search-form-item label="启动人" name="startedBy"/>
        <f-search-form-item label="状态" name="finished" type="select" :data="processInstanceState"></f-search-form-item>
      </f-search-form>
      <f-table ref="table" rowKey="id" :columns="columns" :multiple="false" :operator="operator" :params="queryParam" :api="api.processInstance">
        <span slot="action" slot-scope="text,record">
          <template>
              <a @click="$refs.drawer.handleShow(record)">查看</a>
            <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a href="javascript:;" @click="processImg(record)">流程图</a>
              </a-menu-item>
              <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="$refs.table.del(record)">删除</a>
              </a-menu-item>
                <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="deleteInstance(record)">删除(含历史)</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </f-table>
      <process-instance-drawer ref="drawer"></process-instance-drawer>
      <process-image ref="processImg" v-if="processImageVisible" :visible.sync="processImageVisible" :processInstanceId="processInstanceId"></process-image>
    </a-card>
  </div>
</template>
<script>

  import api from './js/api'
  import ProcessImage from '../process/process_image'
  import ProcessInstanceDrawer from './processInstance_drawer'


  export default {
    name: 'TableList',
    components: {
      ProcessInstanceDrawer,
      ProcessImage

    },
    data() {
      let me = this
      //操作按钮
      let operator = []
      operator.push({
        name: '删除',
        icon: 'delete',
        batch: true,
        handler: function(table) {
          table.remove()
        }
      })
      return {
        api: Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: {},
        processInstanceState: [{ value: false, label: '未结束' }, { value: true, label: '已结束' }],
        processInstanceId: '',
        processImageVisible: false,
        // 表头
        columns: [
          {
            title: '#',
            width: '60',
            align: 'center',
            customRender: (text, record, index) => index + 1
          },
          {
            title: '流程名称',
            align: 'center',
            dataIndex: 'processDefinitionName'
          },
          {
            title: '实例名称',
            align: 'center',
            dataIndex: 'name'
          },
          {
            title: '流程key',
            align: 'center',
            dataIndex: 'processDefinitionKey'
          },

          {
            title: '版本',
            align: 'center',
            dataIndex: 'processDefinitionVersion'
          },
          {
            title: '开始日期',
            align: 'center',
            dataIndex: 'startTime'
          },
          {
            title: '结束日期',
            align: 'center',
            dataIndex: 'endTime'
          },
          {
            title: '操作',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ],
        operator: operator
      }
    },
    created() {
    },
    methods: {
      processImg(processInstance) {
        this.processInstanceId = processInstance.id
        this.processImageVisible = true
      },
      deleteInstance(record) {
        this.$refs.table.del(record, { cascade: true })
      }
    }
  }
</script>
